#region imported Namespaces
using System;
using System.Data;

using BO = PHSRAG.Insight21.BusinessObjects;
using ICachePolicy = PHSRAG.Insight21.Policy.ICachePolicy;
#endregion

namespace PHSRAG.Insight21.Personnel
{
	#region Class Personnel Salary
	/// <summary>
	/// The Personnel Salary class is the facade over the details for an employee's salary data for a given fiscal year
	/// </summary>
	public class PersonnelSalary : BO.BusinessObject
	{
		#region Constants
		private const string SalaryGridKey				= "SalaryGrid_7E9428E5-6B05-477C-A626-5EE0D1CCFF02";
		//Constants to hold the column names
		private const string JobMapIdColumnName			= "EmployeeJobMapId";
		private const string EmployeeNameColumnName		= "EmployeeName";
		private const string CurrentTitleColumnName		= "CurrentTitle";
		private const string CurrentSalaryColumnName	= "CurrentSalary";
		private const string TotalSalaryColumnName		= "TotalSalary";
		private const string ResearchGrantColumnName	= "ResearchGrant";
		private const string ResearchSundryColumnName	= "ResearchSundry";
		private const string DiscretionaryColumnName	= "Discretionary";
		private const string OperatingFundsColumnName	= "OperatingFunds";
		private const string POFundsColumnName			= "POFunds";
		private const string HMSFundsColumnName			= "HMSFunds";
		private const string VAColumnName				= "VA";
		private const string OthersColumnName			= "Other";
		#endregion

		#region Instance variables
		private DataRow salaryGridRow;
		#endregion

		#region Properties
		/// <summary>
		/// Get the job map id associated with the employee.
		/// It is a non nullable field.
		/// </summary>
		public int EmployeeJobMapId
		{
			get
			{
				return (int)salaryGridRow[JobMapIdColumnName];
			}
		}
		/// <summary>
		/// Get the employee's name
		/// </summary>
		public string EmployeeName
		{
			get
			{
				return salaryGridRow[EmployeeNameColumnName].ToString();
			}
		}
		/// <summary>
		///  Get Current Title of the Employee
		///  Return an empty string if there is no current title associated with the employee
		/// </summary>
		public string CurrentTitle
		{
			get
			{
				object currentTitle = salaryGridRow[CurrentTitleColumnName];
				return (currentTitle == DBNull.Value) ? string.Empty : currentTitle.ToString();
			}
		}
		/// <summary>
		/// Get the annual Salary of the employee.
		/// Return 0 if there is no annual salary allocated to the employee
		/// </summary>
		public decimal CurrentSalary
		{
			get
			{
				object currentSalary = salaryGridRow[CurrentSalaryColumnName];
				return (currentSalary == DBNull.Value) ? 0 : (decimal)currentSalary;
			}
		}
		/// <summary>
		/// Get the total Salary for the employee in the given fiscal year
		/// Return 0 if there is no total salary
		/// </summary>
		public decimal TotalSalary
		{
			get
			{
				object totalSalary = salaryGridRow[TotalSalaryColumnName];
				return (totalSalary == DBNull.Value) ? 0 : (decimal)totalSalary;
			}
		}
		/// <summary>
		/// Research Grant
		/// </summary>
		public decimal ResearchGrant
		{
			get
			{
				object researchGrant = salaryGridRow[ResearchGrantColumnName];
				return (researchGrant == DBNull.Value) ? 0 : (decimal)researchGrant;
			}
		}
		/// <summary>
		/// Research Sundry
		/// </summary>
		public decimal ResearchSundry
		{
			get
			{
				object researchSundry = salaryGridRow[ResearchSundryColumnName];
				return (researchSundry == DBNull.Value) ? 0 : (decimal)researchSundry;
			}
		}
		/// <summary>
		/// Discretionary / Sundry
		/// </summary>
		public decimal Discretionary
		{
			get
			{
				object discretionary = salaryGridRow[DiscretionaryColumnName];
				return (discretionary == DBNull.Value) ? 0 : (decimal)discretionary;
			}
		}
		/// <summary>
		/// Operating Funds
		/// </summary>
		public decimal OperatingFunds
		{
			get
			{
				object operatingFunds = salaryGridRow[OperatingFundsColumnName];
				return (operatingFunds == DBNull.Value) ? 0 : (decimal)operatingFunds;
			}
		}
		/// <summary>
		/// PO Funds
		/// </summary>
		public decimal POFunds
		{
			get
			{
				object poFunds = salaryGridRow[POFundsColumnName];
				return (poFunds == DBNull.Value) ? 0 : (decimal)poFunds;
			}
		}
		/// <summary>
		/// HMS Funds
		/// </summary>
		public decimal HMSFunds
		{
			get
			{
				object hmsFunds = salaryGridRow[HMSFundsColumnName];
				return (hmsFunds == DBNull.Value) ? 0 : (decimal)hmsFunds;
			}
		}
		/// <summary>
		/// VA
		/// </summary>
		public decimal VA
		{
			get
			{
				object va = salaryGridRow[VAColumnName];
				return (va == DBNull.Value) ? 0 : (decimal)va;
			}
		}
		/// <summary>
		/// Other
		/// </summary>
		public decimal Other
		{
			get
			{
				object other = salaryGridRow[OthersColumnName];
				return (other == DBNull.Value) ? 0 : (decimal)other;
			}
		}
		#endregion

		#region Constructor
		/// <summary>
		/// Initialize the base class with the specified cache policy and assign the DataRow to the instance variable
		/// </summary>
		/// <param name="cachePolicy">Prevalent cache policy</param>
		/// <param name="dataRow">DataRow containing salary grid data</param>
		public PersonnelSalary(ICachePolicy cachePolicy,DataRow dataRow) : base(cachePolicy)
		{
			salaryGridRow = dataRow;
		}
		#endregion		

		#region Business Object Methods
		/// <summary>
		/// Cache the salary Grid object using the prevalent cache policy
		/// </summary>
		public override void Cache()
		{
			CachePolicy.Cache(SalaryGridKey, this);
		}
		/// <summary>
		/// Remove the SalaryGrid instance from the cache using the prevalent cache policy
		/// </summary>
		public override void UnCache()
		{
			CachePolicy.UnCache(SalaryGridKey);
		}/// <summary>
		/// This method is not used and only exists to satisfy interface requirements.
		/// </summary>
		public override void Load(string connectionString, params object[] args)
		{			
			throw new Exception("SalaryGrid cannot be directly loaded.");
		}
		#endregion
	}
	#endregion
}
